home *** CD-ROM | disk | FTP | other *** search
/ Chip 2006 July / CHIP 2006-07.2.iso / program / web_gelistirme / easyphp1-7_setup.exe / {app} / phpmyadmin / db_datadict.php < prev    next >
Encoding:
PHP Script  |  2003-09-07  |  10.5 KB  |  338 lines

  1. <?php
  2. /* $Id: db_datadict.php,v 1.13 2003/07/19 10:56:21 lem9 Exp $ */
  3.  
  4.  
  5. /**
  6.  * Gets the variables sent or posted to this script, then displays headers
  7.  */
  8. if (!isset($selected_tbl)) {
  9.     include('./libraries/grab_globals.lib.php');
  10.     include('./header.inc.php');
  11. }
  12.  
  13.  
  14. /**
  15.  * Gets the relations settings
  16.  */
  17. require('./libraries/relation.lib.php');
  18. require('./libraries/transformations.lib.php');
  19.  
  20. $cfgRelation  = PMA_getRelationsParam();
  21.  
  22. /**
  23.  * Check parameters
  24.  */
  25. PMA_checkParameters(array('db'));
  26.  
  27. /**
  28.  * Defines the url to return to in case of error in a sql statement
  29.  */
  30. if (isset($table)) {
  31.     $err_url = 'tbl_properties.php?' . PMA_generate_common_url($db, $table);
  32. } else {
  33.     $err_url = 'db_details.php?' . PMA_generate_common_url($db);
  34. }
  35.  
  36. if ($cfgRelation['commwork']) {
  37.     $comment = PMA_getComments($db);
  38.  
  39.     /**
  40.      * Displays DB comment
  41.      */
  42.     if (is_array($comment)) {
  43.         ?>
  44.     <!-- DB comment -->
  45.     <p><?php echo $strDBComment; ?> <i>
  46.         <?php echo htmlspecialchars(implode(' ', $comment)) . "\n"; ?>
  47.     </i></p>
  48.         <?php
  49.     } // end if
  50. }
  51.  
  52. /**
  53.  * Selects the database and gets tables names
  54.  */
  55. PMA_mysql_select_db($db);
  56. $sql    = 'SHOW TABLES FROM ' . PMA_backquote($db);
  57. $rowset = @PMA_mysql_query($sql);
  58.  
  59. if (!$rowset) {
  60.     exit();
  61. }
  62. $count  = 0;
  63. while ($row = mysql_fetch_array($rowset)) {
  64.     if (PMA_MYSQL_INT_VERSION >= 32303) {
  65.         $myfieldname = 'Tables_in_' . htmlspecialchars($db);
  66.     }
  67.     else {
  68.         $myfieldname = 'Tables in ' . htmlspecialchars($db);
  69.     }
  70.     $table        = $row[$myfieldname];
  71.     if ($cfgRelation['commwork']) {
  72.         $comments = PMA_getComments($db, $table);
  73.     }
  74.  
  75.     if ($count != 0) {
  76.         echo '<div style="page-break-before: always">' . "\n";
  77.     }
  78.     echo '<h1>' . $table . '</h1>' . "\n";
  79.  
  80.     /**
  81.      * Gets table informations
  82.      */
  83.     // The 'show table' statement works correct since 3.23.03
  84.     if (PMA_MYSQL_INT_VERSION >= 32303) {
  85.          $local_query  = 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'';
  86.          $result       = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
  87.          $showtable    = PMA_mysql_fetch_array($result);
  88.          $num_rows     = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
  89.          $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
  90.     } else {
  91.          $local_query  = 'SELECT COUNT(*) AS count FROM ' . PMA_backquote($table);
  92.          $result       = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
  93.          $showtable    = array();
  94.          $num_rows     = PMA_mysql_result($result, 0, 'count');
  95.          $show_comment = '';
  96.     } // end display comments
  97.     if ($result) {
  98.          mysql_free_result($result);
  99.     }
  100.  
  101.  
  102.     /**
  103.      * Gets table keys and retains them
  104.      */
  105.     $local_query  = 'SHOW KEYS FROM ' . PMA_backquote($table);
  106.     $result       = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
  107.     $primary      = '';
  108.     $indexes      = array();
  109.     $lastIndex    = '';
  110.     $indexes_info = array();
  111.     $indexes_data = array();
  112.     $pk_array     = array(); // will be use to emphasis prim. keys in the table
  113.                              // view
  114.     while ($row = PMA_mysql_fetch_array($result)) {
  115.         // Backups the list of primary keys
  116.         if ($row['Key_name'] == 'PRIMARY') {
  117.             $primary   .= $row['Column_name'] . ', ';
  118.             $pk_array[$row['Column_name']] = 1;
  119.         }
  120.         // Retains keys informations
  121.         if ($row['Key_name'] != $lastIndex ){
  122.             $indexes[] = $row['Key_name'];
  123.             $lastIndex = $row['Key_name'];
  124.         }
  125.         $indexes_info[$row['Key_name']]['Sequences'][]     = $row['Seq_in_index'];
  126.         $indexes_info[$row['Key_name']]['Non_unique']      = $row['Non_unique'];
  127.         if (isset($row['Cardinality'])) {
  128.             $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
  129.         }
  130.         // I don't know what does following column mean....
  131.         // $indexes_info[$row['Key_name']]['Packed']          = $row['Packed'];
  132.  
  133.         if (PMA_MYSQL_INT_VERSION >= 32300) {
  134.             // rabus: The 'Comment' field was added in MySQL 3.23.0.
  135.             $indexes_info[$row['Key_name']]['Comment']     = $row['Comment'];
  136.         }
  137.  
  138.         $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name']  = $row['Column_name'];
  139.         if (isset($row['Sub_part'])) {
  140.             $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
  141.         }
  142.  
  143.     } // end while
  144.     if ($result) {
  145.         mysql_free_result($result);
  146.     }
  147.  
  148.  
  149.     /**
  150.      * Gets fields properties
  151.      */
  152.     $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table);
  153.     $result      = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
  154.     $fields_cnt  = mysql_num_rows($result);
  155.  
  156.     // Check if we can use Relations (Mike Beck)
  157.     if (!empty($cfgRelation['relation'])) {
  158.         // Find which tables are related with the current one and write it in
  159.         // an array
  160.         $res_rel = PMA_getForeigners($db, $table);
  161.  
  162.         if (count($res_rel) > 0) {
  163.             $have_rel = TRUE;
  164.         } else {
  165.             $have_rel = FALSE;
  166.         }
  167.     }
  168.     else {
  169.         $have_rel = FALSE;
  170.     } // end if
  171.  
  172.  
  173.     /**
  174.      * Displays the comments of the table if MySQL >= 3.23
  175.      */
  176.     if (!empty($show_comment)) {
  177.         echo $strTableComments . ' : ' . $show_comment . '<br /><br />';
  178.     }
  179.  
  180.     /**
  181.      * Displays the table structure
  182.      */
  183.     ?>
  184.  
  185. <!-- TABLE INFORMATIONS -->
  186. <table width="100%" bordercolorlight="black" border="border" style="border-collapse: collapse;background-color: white">
  187. <tr>
  188.     <th width="50"><?php echo $strField; ?></th>
  189.     <th width="80"><?php echo $strType; ?></th>
  190.     <!--<th width="50"><?php echo $strAttr; ?></th>-->
  191.     <th width="40"><?php echo $strNull; ?></th>
  192.     <th width="70"><?php echo $strDefault; ?></th>
  193.     <!--<th width="50"><?php echo $strExtra; ?></th>-->
  194.     <?php
  195.     echo "\n";
  196.     if ($have_rel) {
  197.         echo '    <th>' . $strLinksTo . '</th>' . "\n";
  198.     }
  199.     if ($cfgRelation['commwork']) {
  200.         echo '    <th>' . $strComments . '</th>' . "\n";
  201.     }
  202.     if ($cfgRelation['mimework']) {
  203.         echo '    <th>MIME</th>' . "\n";
  204.     }
  205.     ?>
  206. </tr>
  207.  
  208.     <?php
  209.     $i = 0;
  210.     while ($row = PMA_mysql_fetch_array($result)) {
  211.         $bgcolor = ($i % 2) ?$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
  212.         $i++;
  213.  
  214.         $type             = $row['Type'];
  215.         // reformat mysql query output - staybyte - 9. June 2001
  216.         // loic1: set or enum types: slashes single quotes inside options
  217.         if (eregi('^(set|enum)\((.+)\)$', $type, $tmp)) {
  218.             $tmp[2]       = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
  219.             $type         = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
  220.             $type_nowrap  = '';
  221.  
  222.             $binary       = 0;
  223.             $unsigned     = 0;
  224.             $zerofill     = 0;
  225.         } else {
  226.             $binary       = eregi('BINARY', $row['Type'], $test);
  227.             $unsigned     = eregi('UNSIGNED', $row['Type'], $test);
  228.             $zerofill     = eregi('ZEROFILL', $row['Type'], $test);
  229.             $type_nowrap  = ' nowrap="nowrap"';
  230.             $type         = eregi_replace('BINARY', '', $type);
  231.             $type         = eregi_replace('ZEROFILL', '', $type);
  232.             $type         = eregi_replace('UNSIGNED', '', $type);
  233.             if (empty($type)) {
  234.                 $type     = ' ';
  235.             }
  236.         }
  237.         $strAttribute     = ' ';
  238.         if ($binary) {
  239.             $strAttribute = 'BINARY';
  240.         }
  241.         if ($unsigned) {
  242.             $strAttribute = 'UNSIGNED';
  243.         }
  244.         if ($zerofill) {
  245.             $strAttribute = 'UNSIGNED ZEROFILL';
  246.         }
  247.         if (!isset($row['Default'])) {
  248.             if ($row['Null'] != '') {
  249.                 $row['Default'] = '<i>NULL</i>';
  250.             }
  251.         } else {
  252.             $row['Default'] = htmlspecialchars($row['Default']);
  253.         }
  254.         $field_name = htmlspecialchars($row['Field']);
  255.         echo "\n";
  256.         ?>
  257. <tr>
  258.     <td width=50 class='print' nowrap="nowrap">
  259.         <?php
  260.         echo "\n";
  261.         if (isset($pk_array[$row['Field']])) {
  262.             echo '    <u>' . $field_name . '</u> ' . "\n";
  263.         } else {
  264.             echo '    ' . $field_name . ' ' . "\n";
  265.         }
  266.         ?>
  267.     </td>
  268.     <td width="80" class="print"<?php echo $type_nowrap; ?>><?php echo $type; ?><bdo dir="ltr"></bdo></td>
  269.     <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $strAttribute; ?></td>-->
  270.     <td width="40" class="print"><?php echo (($row['Null'] == '') ? $strNo : $strYes); ?> </td>
  271.     <td width="70" class="print" nowrap="nowrap"><?php if (isset($row['Default'])) echo $row['Default']; ?> </td>
  272.     <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $row['Extra']; ?> </td>-->
  273.         <?php
  274.         echo "\n";
  275.         if ($have_rel) {
  276.             echo '    <td class="print">';
  277.             if (isset($res_rel[$field_name])) {
  278.                 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
  279.             }
  280.             echo ' </td>' . "\n";
  281.         }
  282.         if ($cfgRelation['commwork']) {
  283.             echo '    <td class="print">';
  284.             if (isset($comments[$field_name])) {
  285.                 echo htmlspecialchars($comments[$field_name]);
  286.             }
  287.             echo ' </td>' . "\n";
  288.         }
  289.         if ($cfgRelation['mimework']) {
  290.             $mime_map = PMA_getMIME($db, $table, true);
  291.  
  292.             echo '    <td class="print">';
  293.             if (isset($mime_map[$field_name])) {
  294.                 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
  295.             }
  296.             echo ' </td>' . "\n";
  297.         }
  298.         ?>
  299. </tr>
  300.         <?php
  301.     } // end while
  302.     mysql_free_result($result);
  303.  
  304.     echo "\n";
  305.     ?>
  306. </table>
  307.  
  308.     <?php
  309.     echo '</div>' . "\n";
  310.  
  311.     $count++;
  312. } //ends main while
  313.  
  314.  
  315. /**
  316.  * Displays the footer
  317.  */
  318. echo "\n";
  319. ?>
  320. <script type="text/javascript" language="javascript1.2">
  321. <!--
  322. function printPage()
  323. {
  324.     document.all.print.style.visibility = 'hidden';
  325.     // Do print the page
  326.     if (typeof(window.print) != 'undefined') {
  327.         window.print();
  328.     }
  329.     document.all.print.style.visibility = '';
  330. }
  331. //-->
  332. </script>
  333. <?php
  334. echo '<br /><br /> <input type="button" style="visibility: ; width: 100px; height: 25px" name="print" value="' . $strPrint . '" onclick="printPage()">' . "\n";
  335.  
  336. require('./footer.inc.php');
  337. ?>
  338.